// xTester.cpp : Implementation of WinMain


#include "stdafx.h"
#include "AutoDo.h"
#include "log_test.h"


// The module attribute causes WinMain to be automatically implemented for you
[ module(exe, uuid = "{4D261217-3F7C-41D6-BD07-FAB40D26D930}", 
         name = "xTester", 
         helpstring = "xTester 1.0 Type Library") ]
class CxTesterModule
{
public:
    // Override CAtlExeModuleT members
    HRESULT Run(int nShowCmd)
    {
        CxAutoDo _autoDo;

        xDll::XDll_RegisterObjectsAndServices();
        xKernel::xKernel_RegisterObjectsAndServices();

        //CComPtr<IxTest> spTest;
        //::xCommon::CreateObjectByIID(__uuidof(IxTest), (void**)&spTest);
        //if (spTest)
        //    spTest->Test();

        //CComPtr<IxTestService> spTestService;
        //::xCommon::GetService(__uuidof(IxTestService), (void**)&spTestService);
        //if (spTestService)
        //    spTestService->Test();

        TestLog();

        CComPtr<IxBuilder> spBuilder;
        ::xCommon::GetService(__uuidof(IxBuilder), (void**)&spBuilder);
        if (spBuilder)
        {
            CComPtr<IxElement> spElement;
            spBuilder->CreateFromFile(CComBSTR(_T("../resource/ui.xml|main")), (IUnknown**)&spElement);

            CComQIPtr<IxWnd> spWnd = spElement;
            if (spWnd)
            {
                spWnd->CreateWnd();

                CComPtr<IxMessageLoop> spLoop;
                ::xCommon::GetService(__uuidof(IxMessageLoop), (void**)&spLoop);
                if (spLoop)
                    spLoop->Run();
            }
        }

        /*
        CComPtr<IxWnd> spWnd;
        ::xCommon::CreateObjectByIID(__uuidof(IxWnd), (void**)&spWnd);
        if (spWnd)
            spWnd->CreateWnd();

        CComPtr<IxBrushView> spBrushView;
        ::xCommon::CreateObjectByIID(__uuidof(IxBrushView), (void**)&spBrushView);
        if (spBrushView)
            spBrushView->SetColor(RGB(100,100,200));

        CComPtr<IxBrushView> spBrushView1;
        ::xCommon::CreateObjectByIID(__uuidof(IxBrushView), (void**)&spBrushView1);
        if (spBrushView1)
            spBrushView1->SetColor(RGB(100,200,100));

        CComQIPtr<IxNode> spNode = spWnd;

        CComQIPtr<IxView> spView = spBrushView;
        if (spView)
        {
            spView->SetSize(CSize(500,400));
            spView->SetFocusState(TRUE);
            if (spNode)
                spNode->AddChild(CComQIPtr<IxNode>(spView));
        }

        spView = spBrushView1;
        if (spView)
        {
            spView->SetBorder(CRect(1,1,1,1));
            spView->SetBorderColor(RGB(0,255,255));
            spView->SetSize(CSize(500,400));
            spView->SetAlignment(xKernel::E_ALIGNMENT_RIGHT | xKernel::E_ALIGNMENT_TOP);
            if (spNode)
                spNode->AddChild(CComQIPtr<IxNode>(spView));
        }

        CComPtr<IxFileManager> spFileMgr;
        ::xCommon::GetService(__uuidof(IxFileManager), (void**)&spFileMgr);
        if (spFileMgr)
        {
            spFileMgr->RegisterSymbolPath(CComBSTR(_T("Skin")), CComBSTR(_T("..\\resource")), 0);
        }

        CComPtr<IxView> spViewObj;
        ::xCommon::CreateObjectByIID(__uuidof(IxView), (void**)&spViewObj);
        if (spViewObj)
        {
//             CComPtr<IxBrush> spBrush;
//             ::xCommon::CreateObjectByIID(__uuidof(IxBrush), (void**)&spBrush);
//             if (spBrush)
//             {
//                 spBrush->SetColor(RGB(200,200,90));
//                 spViewObj->SetNormalDraw(spBrush);
//             }

            CComPtr<IxTexture> spTexture;
            ::xCommon::CreateObjectByIID(__uuidof(IxTexture), (void**)&spTexture);
            if (spTexture)
            {
                spTexture->SetFile(L"Skin:\\1.jpg");
                spViewObj->SetNormalDraw(spTexture);
            }

            spViewObj->SetBorder(CRect(1,1,1,1));
            spViewObj->SetBorderColor(RGB(0,255,255));
            spViewObj->SetSize(CSize(500,400));
            spViewObj->SetAlignment(xKernel::E_ALIGNMENT_RIGHT | xKernel::E_ALIGNMENT_BOTTOM);
            if (spNode)
                spNode->AddChild(CComQIPtr<IxNode>(spViewObj));
        }

        CComPtr<IxMessageLoop> spLoop;
        ::xCommon::GetService(__uuidof(IxMessageLoop), (void**)&spLoop);
        if (spLoop)
            spLoop->Run();

        */

        return S_OK;
    }
};
